package com.efast.dmom.aps.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.aps.bean.ProductRoute;
import com.efast.dmom.aps.bean.ResultBean;
import com.efast.dmom.aps.entity.ProductRouteEntity;
import com.efast.dmom.aps.entity.base.IModificationFlags;
import com.efast.dmom.aps.service.ProductRouteService;

@Controller
@RequestMapping("/productRoute")
public class ProductRouteController {

	@Autowired
	private ProductRouteService productRouteService;

	@RequestMapping(value = "/operateByProductRoute")
	public @ResponseBody ResultBean operateByProductRoute(@RequestBody ProductRoute productRoute) {
		
		ProductRouteEntity entity = productRoute.getInnerData();
		// Determine the new
		if (entity.getModificationFlag() == IModificationFlags.NEW) {
			return productRouteService.save(productRoute);
			// Judge update
		} else if (entity.getModificationFlag() == IModificationFlags.MODIFIED) {
			return productRouteService.update(productRoute);
			// Judge to delete
		} else if (entity.getModificationFlag() == IModificationFlags.DELETED) {
			return productRouteService.delete(productRoute);
		}
		return null;
	}

	// get productRoute relation by id
	@RequestMapping(value = "/getProductRouteById/{id}")
	public @ResponseBody ProductRoute getProductRouteById(@PathVariable long id) {
		return productRouteService.getById(id);
	}

}
